<template>
	<view>
		<JobForm ref="child" type="edit" @submit="submit"></JobForm>
		<u-top-tips ref="uTips"></u-top-tips>
	</view>
</template>

<script>
import JobForm from './components/JobForm';
import http from '@/utils/http';
import api from '@/api';
export default {
	name: 'EditJob',
	components: {
		JobForm
	},
	data() {
		return {};
	},
	onLoad(e){
		this.fetchData(e.id);
	},
	mounted() {
	},
	methods: {
		fetchData(id) {
			http.get(api.company_jobedit_pre, { id })
				.then(res => {
					this.$refs.child.basic = res.data.data.basic;
					this.$refs.child.contact = res.data.data.contact;
					this.$refs.child.field_rule = res.data.data.field_rule;
					this.$refs.child.restoreCondition({
						basic: res.data.data.basic,
						contact: res.data.data.contact,
						field_rule: res.data.data.field_rule
					});
				})
				.catch(() => {});
		},
		submit(values) {
			http.post(api.company_jobedit_save, values)
				.then(res => {
					this.$refs.uTips.show({
						title: res.data.message,
						type: 'success'
					});
					setTimeout(() => {
						uni.navigateBack({
							delta: 1
						});
					}, 1500);
				})
				.catch(() => {});
		}
	}
};
</script>
